package adventure.commands;

import adventure.*;
import adventure.room.RoomManager;
import player.*;
import server.util.Broadcaster;

/**
 *
 * @author Michael Hanns
 *
 */
public abstract class AbstractCommand {

    protected Adventure adv;
    protected RoomManager rooms;
    protected PlayerManager players;
    protected Broadcaster out;
    protected String[] synonyms;
  

    public AbstractCommand(Adventure a, String[] input) {
        this.adv = a;
        this.rooms = ((AdventureEdit) a).getRoomManager();
        this.players = ((AdventureEdit) a).getPlayerManager();
        this.out = ((AdventureEdit) a).getBroadcaster();
        this.synonyms = input;

        for(int x = 0; x < synonyms.length; x++) {
            synonyms[x] = synonyms[x].toUpperCase();
        }
    }
    
    public void setPlayerManager(PlayerManager players) {
        this.players = players;
    }
    
    public void setBroadcaster(Broadcaster out) {
        this.out = out;
    }

    public boolean isCommand(String command) {
        for (int c = 0; c < synonyms.length; c++) {
            if (synonyms[c].startsWith(command.toUpperCase())) {
                return true;
            }
        }
        return false;
    }

    public abstract String validateAndExecute(Player p, String[] commandAndArgs);

}
